<?php

namespace app\admins\controller;

use think\Controller;
use Util\SysDb;

class Userinfo extends Controller
{
    public function doSession()
    {
        $id = trim(input('param.username'));
        $this->db = new SysDb();
        $h = $this->db->table('admins')->where(['username' => $id])->item();
        exit(json_encode($h));
    }

    public function userChange()
    {
        $id = trim(input('param.username'));
        $realname = trim(input('param.realname'));
        $sex = trim(input('param.sex'));
        $phone = trim(input('param.phone'));
        $userBirthday = trim(input('param.userBirthday'));
        $email = trim(input('param.email'));
        $userImg = trim(input('param.userImg'));
        $data['realname'] = $realname;
        $data['sex'] = $sex;
        $data['phone'] = $phone;
        $data['userBirthday'] = $userBirthday;
        $data['email'] = $email;
        $data['userImg'] = $userImg;

        $this->db = new SysDb();
        $change = $this->db->table('admins')->where(['username' => $id])->update($data);
        if ($change) {
            exit(json_encode(['code' => 0, 'msg' => '提交成功']));
        } else {
            exit(json_encode(['code' => 2, 'msg' => '提交失败']));
        }
    }
}
